/**
 * Created by Administrator on 2017/10/19.
 */
$(document).ready(function () {
    $('#elm1').xheditor({
        html5Upload: false,
        upLinkUrl: "/findAdmin/admin/imageUpload",
        upLinkExt: "zip,rar,txt",
        upImgUrl: "/findAdmin/admin/imageUpload",
        upImgExt: "jpg,jpeg,gif,png",
        upFlashUrl: "/findAdmin/admin/imageUpload",
        upFlashExt: "swf,mp3",
        upMediaUrl: "/findAdmin/admin/imageUpload",
        upMediaExt: "wmv,avi,wma,mp3,mid",
        onUpload: insertUpload
    });
    $('.choice').click(function () {
        $('#titleImg').trigger('click');
    });
    $('#titleImg').change(function () {
        var objUrl = getObjectURL(this.files[0]);
        var reader = new FileReader();
        var size = this.files[0].size / (1024 * 1024);
        reader.readAsDataURL(document.getElementById('titleImg').files[0]);
        reader.onload = function (theFile) {
            var image = new Image();
            image.src = theFile.target.result;
            image.onload = function () {
                // console.log("图片的宽度为"+this.width+",长度为"+this.height);
                if (this.width >= 960 && this.height >= 480 && size < 1) {
                    if (objUrl) {
                        $('.img_view').attr("src", theFile.target.result);//objUrl
                        $('.showImg').show();
                    }
                } else {
                    tips_div("请选择合适的尺寸上传", 2000);
                }
            };
        };

    });
    var editor;
    editor = $('#elm1')[0].xheditor;
    var textArea = editor.getSource();//文本内容·

    function insertUpload(arrMsg) {
        console.log(arrMsg);
    }

});

function tips_div(text, time) {
    $('.tips_div').text(text).show();
    setTimeout(function () {
        $('.tips_div').hide();
    }, time)
}

function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}

